//package com.qiaodata.datatrans.web;
//
//import com.alibaba.fastjson.JSONObject;
//import com.qiaodata.datatrans.entity.QuanZhiResumer;
//import com.qiaodata.datatrans.model.TransRecord;
//import com.qiaodata.datatrans.repository.ResumerRepository;
//import com.qiaodata.datatrans.service.TransRecordService;
//import com.qiaodata.datatrans.transfor.AskInnerService;
//import com.qiaodata.datatrans.transfor.OutDataToFormat;
//import com.qiaodata.datatrans.utils.JsonRet;
//import com.qiaodata.datatrans.utils.StringUtil;
//import io.swagger.annotations.ApiOperation;
//import io.swagger.annotations.ApiParam;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.Date;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * Created by Administrator on 2016/11/15 0015.
// */
//@RestController
//@RequestMapping("/import")
//@Slf4j
//public class ImportDataController {
//
//    @Autowired
//    private OutDataToFormat outDataToFormat;
//    @Autowired
//    private ResumerRepository resumerRepository;
//    @Autowired
//    private TransRecordService transRecordService;
//    @Autowired
//    private AskInnerService askInnerService;
//
//    @ApiOperation("简历导入接口")
//    @RequestMapping(value = "/importData", method = {RequestMethod.POST, RequestMethod.GET})
//    public Object importData(@ApiParam(required = true, name = "jsonObject", value = "包含P_PersonalInformation及P_Resume的大json") @RequestBody JSONObject jsonObject) throws Exception {
//        if (jsonObject==null || "".equals(jsonObject.toString())) {
//            log.debug("传递参数为空！");
//            return JsonRet.getInstance("传递参数为空！");
//        }
//        //初步解析json
//        Map<String, String> qzJson = getQZJson(jsonObject);
//        String p1 = qzJson.get("P_PersonalInformation");
//        String p2 = qzJson.get("P_Resume");
//        if (p1==null || "".equals(p1) || p2==null || "".equals(p2)) {
//            log.debug("传递参数为空！");
//            return JsonRet.getInstance("传递参数为空！");
//        }
//        try {
//            JSONObject parse1 = (JSONObject) JSONObject.parse(p1);
////        System.out.println(parse1);
//            JSONObject parse2 = (JSONObject) JSONObject.parse(p2);
////        System.out.println(parse2);
////            Long refreshTime = outDataToFormat.getRefreshTime(parse1);
////            String email = outDataToFormat.getEmail(parse1);
////            String mobile = outDataToFormat.getMobile(parse1);
////            //判断参数是否为空
////            if (refreshTime==null || email==null || "".equals(email) || mobile==null || "".equals(mobile)) {
////                return JsonRet.getInstance("传递参数为空！");
////            }
////            //调用ask接口，该接口不需要记录日志,flag==0表示巧达新，==1表示全职新，需要入库
////            String flag = askInnerService.getAskResultInner(mobile, email, "" + refreshTime);
////            if (!"1".equals(flag)) {
////                return JsonRet.getInstance("数据入库失败！原因：巧达版本最新！");
////            }
//            long l1 = System.currentTimeMillis();
//            //简历转换
//            QuanZhiResumer resumer = outDataToFormat.getQuanZhiResumer(parse1, parse2);
//            long l2 = System.currentTimeMillis();
//            System.out.print("转换一条用时："+(l2-l1)+"ms");
////        System.out.println(resumer.toString());
//            resumerRepository.save(resumer);
//            log.debug("数据入库成功！");
////            //记录日志
////            TransRecord transRecord = new TransRecord();
////            transRecord.setMobile(mobile);
////            transRecord.setEmail(email);
////            transRecord.setCreateDate(new Date());
////            transRecord.setFlag("1");//入库的是全职版本最新的数据，0表示巧达
////            transRecord.setState("1");//表示该记录是import过程中产生的
////            transRecord.setRefreshTimeInQz(StringUtil.parseInt(""+refreshTime));
////            transRecord.setRefreshTimeOutQd(0);
////            transRecordService.insert(transRecord);
//
//            long l3 = System.currentTimeMillis();
//
//            System.out.print("入库一条用时："+(l3-l2)+"ms");
//            return JsonRet.getInstance("数据入库成功！");
//        } catch (Exception e) {
//            log.error("数据入库失败！");
//            return JsonRet.getInstance("数据入库失败！");
//        }
//    }
//
//    private Map<String, String> getQZJson(JSONObject jsonObject) {
//        Map<String, String> map = new HashMap<>();
//        if (jsonObject==null || "".equals(jsonObject.toString())) {
//            map.put("P_PersonalInformation", "");
//            map.put("P_Resume", "");
//            return map;
//        }
//        String[] split = jsonObject.toString().split("P_PersonalInformation\":");
//        if (split.length<2) {
//            map.put("P_PersonalInformation", "");
//            map.put("P_Resume", "");
//            return map;
//        }
//        String[] split1 = split[1].split("P_Resume\":");
//        if (split1.length<2) {
//            map.put("P_PersonalInformation", "");
//            map.put("P_Resume", "");
//            return map;
//        }
//        String p1 = split1[0].substring(0, split1[0].length() - 2);
//        String p2 = split1[1].substring(0, split1[1].length() - 1);
//        map.put("P_PersonalInformation", p1);
//        map.put("P_Resume", p2);
//        return map;
//    }
//
//}
